//
//  BRRequest.m
//  ZhuShou
//
//  Created by Dejun Liu on 15/11/16.
//  Copyright © 2015年 jw. All rights reserved.
//

#import "BRServiceCenter.h"

@implementation BRServiceCenter

+ (void)BRServiceCenterUPDWithAction:(NSString *)action CMD:(UInt16)cmd params:(NSDictionary *)aParams response:(ResponseBlock) block
{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:aParams];
    [params hs_setSafeValue:@"iOS" forKey:@"clientId"];
    [params hs_setSafeValue:action forKey:@"req"];
    [params hs_setSafeValue:@"0.0.0.0" forKey:@"userIp"];
    [params hs_setSafeValue:[[NSDate date] dateTimeMilliSecondString] forKey:@"clientTime"];
    [params hs_setSafeValue:[[NSString stringWithFormat:@"%@%@%@",
                              [params objectForKey:@"name"],
                              [params objectForKey:@"value"],
                              [[NSDate date] string]] md5] forKey:@"s"];
    [params hs_setSafeValue:@"" forKey:@""];
    [params hs_setSafeValue:@"" forKey:@""];
    
    [[BRUDPService sharedInstance]sendMessageDictionary:params cmd:cmd timeout:3 retryCount:3 response:^(BRMessageResponseType type, NSInteger retryCount, id responseObj) {
        if (block) {
            NSDictionary *jsonObj = [responseObj JSONObject];
            dispatch_async(dispatch_get_main_queue(), ^{
                block(type,retryCount,[BRUDPResponse UDPResponseWithDictionary:jsonObj]);
            });
        }
    }];

    /*
    {clientId:"iOS", req:"manipulateDevice", type:"mainframe", name:"insert",
    value:[location:"客厅", registerCode:"C0000001"], userIp:"1.2.3.4",
        clientTime:"2015-11-09 10:26:55.078", s:"xxx"}
    
    {clientId:"iOS", req:"register", type:"email", name:"abc@def.com",
        value:"123456", userIp:"1.2.3.4", clientTime:"2015-10-24 15:40:12.789", s:"xxx"}
     */
}

@end
